﻿' LibWowHeroes
' by Ronald M. Clifford (roncli@roncli.com)
'
' This source code is released under the GNU Library General Public License (LGPL) Version 2.1.

Imports System.IO
Imports System.Net

Namespace roncliProductions.LibWowHeroes

    ''' <summary>
    ''' The base class to inherit WoW Heroes info from
    ''' </summary>
    ''' <remarks></remarks>
    Public MustInherit Class WowHeroesData

        Protected strData As String

        ''' <summary>
        ''' The URL that will open the appropriate WoW Heroes page
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public MustOverride ReadOnly Property URL() As String

        ''' <summary>
        ''' Retrieves the data based on the supplied query
        ''' </summary>
        ''' <remarks></remarks>
        Protected Sub Retrieve()
            Dim hwrRequest As HttpWebRequest = CType(HttpWebRequest.Create(URL), HttpWebRequest)
            hwrRequest.Accept = "*/*"
            hwrRequest.UserAgent = "MSIE 7.0"
            hwrRequest.Headers.Add(HttpRequestHeader.AcceptLanguage, "en-us")
            hwrRequest.Headers.Add(HttpRequestHeader.Pragma, "no-cache")
            hwrRequest.Timeout = 10000
            Try
                Using wrResponse As WebResponse = hwrRequest.GetResponse()
                    Using srReader As New StreamReader(wrResponse.GetResponseStream())
                        strData = srReader.ReadToEnd()
                    End Using
                End Using
            Catch wex As WebException
                If CType(wex.Response, HttpWebResponse).StatusCode = HttpStatusCode.NotFound Then
                    strData = ""
                Else
                    Throw wex
                End If
            End Try
            hwrRequest = Nothing
        End Sub

    End Class

End Namespace